home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTValMap<K,T,C> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tvmap.h> RWTValMap<K,T,C> m; SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy DDDDeeeeppppeeeennnnddddeeeennnntttt!!!! RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp requires the Standard C++ Library. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a collection of keys, each with an associated item of type TTTT. Order is determined by the key according to a comparison object of type CCCC. CCCC must induce a total ordering on elements of type KKKK via a public member bbbboooooooollll ooooppppeeeerrrraaaattttoooorrrr(((())))((((ccccoooonnnnsssstttt KKKK&&&& xxxx,,,, ccccoooonnnnsssstttt KKKK&&&& yyyy)))) ccccoooonnnnsssstttt which returns ttttrrrruuuueeee if xxxx and its partner should precede yyyy and its partner within the collection. The structure lllleeeessssssss<<<<TTTT>>>> from the C++-standard header file <<<<ffffuuuunnnnccccttttiiiioooonnnnaaaallll>>>> is an example. RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> will not accept a key that compares equal to any key already in the collection. (RRRRWWWWTTTTVVVVaaaallllMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> may contain multiple keys that compare equal to each other.) Equality is based on the comparison object and not on the ======== operator. Given a comparison object ccccoooommmmpppp, keys aaaa and bbbb are equal if !!!!ccccoooommmmpppp((((aaaa,,,,bbbb)))) &&&&&&&& !!!!ccccoooommmmpppp((((bbbb,,,,aaaa)))). PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic. EEEExxxxaaaammmmpppplllleeeessss In this example, a map of RRRRWWWWCCCCSSSSttttrrrriiiinnnnggggs and RRRRWWWWDDDDaaaatttteeees is exercised. // // tvmbday.cpp // #include <rw/tvmap.h> #include <rw/cstring.h> #include <rw/rwdate.h> #include <iostream.h> main(){ RWTValMap<RWCString, RWDate, less<RWCString> > birthdays; birthdays.insert("John", RWDate(12, "April",1975)); birthdays.insert("Ivan", RWDate(2, "Nov", 1980)); // Alternative syntax: PPPPaaaaggggeeee 1111 RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) birthdays["Susan"] = RWDate(30, "June", 1955); birthdays["Gene"] = RWDate(5, "Jan", 1981); // Print a birthday: cout << birthdays["John"] << endl; return 0; } Program Output: RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss 04/12/75 Class RRRRWWWWTTTTVVVVaaaallllMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> offers the same interface to a collection that accepts multiple keys that compare equal to each other. RRRRWWWWTTTTVVVVaaaallllSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> maintains a collection of keys without the associated values. Class mmmmaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC,,,,aaaallllllllooooccccaaaattttoooorrrr>>>> is the C++-standard collection that serves as the underlying implementation for this collection. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss typedef map<K,T,C,allocator> container_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef container_type::size_type size_type; typedef pair <const K,T> value_type; typedef pair <const K,T>& reference; typedef const pair <const K,T>& const_reference; PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(const C& comp = C()); Constructs an empty map with comparator ccccoooommmmpppp. RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(const container_type& m); Constructs a map by copying all elements of mmmm. RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(const RWTValMap<K,T,C>& rwm); Copy constructor. RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(const value_type* first, const value_type* last,const C& comp = C()); Constructs a map by copying elements from the array of vvvvaaaalllluuuueeee____ttttyyyyppppeeee pairs pointed to by ffffiiiirrrrsssstttt, up to, but not including, the pair pointed to by PPPPaaaaggggeeee 2222 RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) llllaaaasssstttt. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTValMap<K,T,C>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTValMap<K,T,C>& m); RWTValMap<K,T,C>& ooooppppeeeerrrraaaattttoooorrrr====(const container_type& m); Destroys all elements of self and replaces them by copying all associations from mmmm.... bool ooooppppeeeerrrraaaattttoooorrrr<<<<(const RWTValMap<K,T,C>& m) const; bool ooooppppeeeerrrraaaattttoooorrrr<<<<(const container_type & m) const; Returns ttttrrrruuuueeee if self compares lexicographically less than mmmm, otherwise returns ffffaaaallllsssseeee. Assumes that type KKKK has well-defined less-than semantics (TTTT::::::::ooooppppeeeerrrraaaattttoooorrrr<<<<((((ccccoooonnnnsssstttt KKKK&&&&)))) or equivalent). bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTValMap<K,T,C>& m) const; bool ooooppppeeeerrrraaaattttoooorrrr========(const container_type & m) const; Returns ttttrrrruuuueeee if self compares equal to mmmm, otherwise returns ffffaaaallllsssseeee. Two collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual pairs that compare equal to each other. T& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](const K& key); Looks up kkkkeeeeyyyy and returns a reference to its associated item. If the key is not in the dictionary, then it will be added with an associated item provided by the default constructor for type TTTT. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const K&, T&, void*),void* d); void aaaappppppppllllyyyy(void (*fn)(const K&, const T&, void*), void* d) const; Applies the user-defined function pointed to by ffffnnnn to every association in the collection. This function must have one of the prototypes: vvvvooooiiiidddd yyyyoooouuuurrrrffffuuuunnnn((((ccccoooonnnnsssstttt KKKK&&&& kkkkeeeeyyyy,,,, TTTT&&&& aaaa,,,, vvvvooooiiiidddd**** dddd))));;;; vvvvooooiiiidddd yyyyoooouuuurrrrffffuuuunnnn((((ccccoooonnnnsssstttt KKKK&&&& kkkkeeeeyyyy,,,, ccccoooonnnnsssstttt TTTT&&&& aaaa,,,,vvvvooooiiiidddd**** dddd))));;;; Client data may be PPPPaaaaggggeeee 3333 RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) passed through parameter dddd. void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(void (*fn)(const K&, T&, void*),void* d); void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee (void (*fn)(const K&, const T&, void*), void* d) const; This is a deprecated version of the aaaappppppppllllyyyy member above. It behaves exactly the same as aaaappppppppllllyyyy.... iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; Returns an iterator positioned at the first pair in self. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. Each key and its associated item will have its destructor called. bool ccccoooonnnnttttaaaaiiiinnnnssss(const K& key) const; Returns ttttrrrruuuueeee if there exists a key jjjj in self that compares equal to kkkkeeeeyyyy, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(const_reference,void*), void* d) const; Returns ttttrrrruuuueeee if there exists an association a in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. PPPPaaaaggggeeee 4444 RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last association in self. size_type eeeennnnttttrrrriiiieeeessss() const; Returns the number of associations in self. bool ffffiiiinnnndddd(const K& key, Key& r) const; If there exists a key jjjj in self that compares equal to kkkkeeeeyyyy, assigns jjjj to rrrr and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the value of rrrr unchanged. bool ffffiiiinnnndddd(bool (*fn)(const_reference,void*), void* d, pair<K,T>& r) const; If there exists an association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, assigns aaaa to rrrr and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the value of kkkk unchanged. ffffnnnn points to a user- defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. bool ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K& key, T& r) const; If there exists a key jjjj in self that compares equal to kkkkeeeeyyyy, assigns the item associated with jjjj to rrrr and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the value of rrrr unchanged. bool ffffiiiinnnnddddKKKKeeeeyyyyVVVVaaaalllluuuueeee(const K& key, K& kr, T& tr) const; PPPPaaaaggggeeee 5555 RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) If there exists a key jjjj in self that compares equal to kkkkeeeeyyyy, assigns jjjj to kkkkrrrr, assigns the item associated with jjjj to trrrr,,,, and returns ttttrrrruuuueeee. Otherwise, returns ffffaaaallllsssseeee and leaves the values of kkkkrrrr and ttttrrrr unchanged. bool iiiinnnnsssseeeerrrrtttt(const K& key, const T& a); Adds kkkkeeeeyyyy with associated item aaaa to the collection. Returns ttttrrrruuuueeee if the insertion is successful, otherwise returns ffffaaaallllsssseeee. The function will return ttttrrrruuuueeee unless the collection already holds an association with the equivalent key. bool iiiinnnnsssseeeerrrrttttKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K& key, const T& a); This is a deprecated version of the iiiinnnnsssseeeerrrrtttt member above. It behaves exactly the same as iiiinnnnsssseeeerrrrtttt. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const K& key) const; Returns the number of keys jjjj in self that compare equal to kkkkeeeeyyyy. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff (bool (*fn)(const_reference&,void*),void* d) const; Returns the number of associations aaaa in self such that the expression((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference& a, void* d); Client data may be passed through parameter dddd. PPPPaaaaggggeeee 6666 RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) bool rrrreeeemmmmoooovvvveeee(const K& key); Removes the first association with key jjjj in self such that jjjj compares equal to kkkkeeeeyyyy and returns ttttrrrruuuueeee. Returns ffffaaaallllsssseeee if there is no such association. bool rrrreeeemmmmoooovvvveeee(bool (*fn)(const_reference,void*), void* d); Removes the first association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee and returns ttttrrrruuuueeee. Returns ffffaaaallllsssseeee if there is no such element. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const K& key); Removes all associations with key j in self such that jjjj compares equal to kkkkeeeeyyyy. Returns the number of items removed. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(const_reference,void*), void* d); Removes all associations aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number of items removed. ffffnnnn points to a user-defined tester function which must have prototype: bool yourTester(const_reference a, void* d); Client data may be passed through parameter dddd. PPPPaaaaggggeeee 7777 RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTVVVVaaaallllMMMMaaaapppp((((3333CCCC++++++++)))) map<K,T,C,allocator>& ssssttttdddd(); const map<K,T,C,allocator>& ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves as the implementation for self. This reference may be used freely, providing access to the C++-standard interface as well as interoperability with other software components that make use of the C++-standard collections. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttoooorrrrssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTValMap<K,T,C>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTValMap<K,T,C>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValMap<K,T,C>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValMap<K,T,C>& coll); Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTValMap<K,T,C>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTValMap<K,T,C>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 8888